package com.example.menulhd;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private String[] names1={"食物11","食物12"};
    private String[] sales1={"销量11","销量12"};
    private String[] prices1={"售价11","售价12"};
    private int[] imgs1={R.drawable.recom_one,R.drawable.recom_two};


    private String[] names2={"食物21","食物22"};
    private String[] sales2={"销量21","销量22"};
    private String[] prices2={"售价21","售价22"};
    private int[] imgs2={R.drawable.must_buy_one,R.drawable.must_buy_two};

    private TextView tv_recommand,tv_must_buy;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setData(); // 封装数据
        init(); // 根据数据初始化界面
        clickEvent();
    }

    private void clickEvent() {
        tv_recommand.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentManager fm = getSupportFragmentManager();
                FragmentTransaction transaction = fm.beginTransaction();
               
            }
        });
        tv_must_buy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
    }

    private void init() {
        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.left);
        tv_recommand = fragment.getView().findViewById(R.id.tv_recommend);
        tv_must_buy = fragment.getView().findViewById(R.id.tv_must_buy);

    }

    private void setData() {
        HashMap<String,List> map = new HashMap<>();
        List<FoodBean> list1 = new ArrayList<>();
        List<FoodBean> list2 = new ArrayList<>();
        for (int i = 0; i < names1.length; i++) {
            FoodBean foodBean = new FoodBean();
            foodBean.setImg(imgs1[i]);
            foodBean.setName(names1[i]);
            foodBean.setPrice(prices1[i]);
            foodBean.setSales(sales1[i]);
            list1.add(foodBean);
        }
        for (int i = 0; i < names2.length; i++) {
            FoodBean foodBean = new FoodBean();
            foodBean.setImg(imgs2[i]);
            foodBean.setName(names2[i]);
            foodBean.setPrice(prices2[i]);
            foodBean.setSales(sales2[i]);
            list2.add(foodBean);
        }
        map.put("1",list1);
        map.put("2",list2);


    }
}